package others;

public class monotoneIncreasingDigits {
    public static int monotoneIncreasingDigits(int n) {

        for(int num=n;num>=0;--num){
            if(isValid(num)){
                return num;
            }
        }
        return 0;
    }

    private static boolean isValid(int num) {
        int pre=num%10;
        num=num/10;
        while (num>0){
            int next=num%10;
            if(pre<next){
                return false;
            }
            num=num/10;
            pre=next;
        }
        return true;
    }

    public static void main(String[] args) {
        System.out.println(isValid(123));
    }
}
